<?php
namespace UCenter\Pages;

use UCenter\UCenter;

class UploadUserAvatar extends \SpecialPage {

	public function __construct() {
		parent::__construct('UploadUserAvatar');
	}

	public function execute($par) {
		$this->requireLogin('prefsnologintext2');

		$this->setHeaders();
		$this->outputHeader();
		$request = $this->getRequest();

		if ($this->getUser()->getBlock()) {
			throw new \UserBlockedError($this->getUser()->getBlock());
		}
		
		$this->displayForm();
	}

	public function displayForm() {
		$uc = new UCenter();
		list($uid, $username, $email) = $uc->uc_get_user($this->getUser()->getName());
		$html = '<iframe frameborder="0" src="' . $uc->uc_change_avatar($uid, 'virtual', false) . '" style="width: 100%; height: 300px"></iframe>';

		$this->getOutput()->addWikiMsg('uploadavatar-notice');
		$this->getOutput()->addHTML($html);
	}

	public function isListed() {
		return false;
	}
}